package com.sz.lk.wingsystem.mvp.presenter;

import com.sz.lk.wingsystem.bean.LoginResult;
import com.sz.lk.wingsystem.mvp.OnNetRequestListener;
import com.sz.lk.wingsystem.mvp.RxPresenter;
import com.sz.lk.wingsystem.mvp.contract.LoginContract;
import com.sz.lk.wingsystem.mvp.model.LoginModel;

/**
 * author : liuke
 * e-mail : 1012459343@qq.com
 * date   : 2020/12/6 14:23
 * desc   :
 * version: 1.0
 */
public class LoginPresenter extends RxPresenter<LoginContract.view> implements LoginContract.Presenter {
    private LoginContract.Model model = new LoginModel(this);

    @Override
    public void Get_Login(String name, String pass) {
        //View是否绑定 如果没有绑定，就不执行网络请求
        if (!isViewAttached()) {
            return;
        }
        model.Login(name, pass, new OnNetRequestListener<LoginResult>() {
            @Override
            public void onStart() {
                mView.showLoading();
            }

            @Override
            public void onFinish() {
                mView.hideLoading();
            }

            @Override
            public void onSuccess(LoginResult data) {
                mView.onLoginSuccess(data);
            }

            @Override
            public void onFailure(Throwable t) {
                mView.onError(t);
            }
        });
    }
}